<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="css/eui.css">
    <style>
        body{
            background-image: url("imgs/d.jpg");
            background-size: cover;/*cover是专门用来设置全屏背景的*/
            margin-top: 200px;
            margin-left: 100px;
            text-align: center;
        }
        img{
            width: 100px;
        }

        .el-form-item__label {
            text-align: right;
            vertical-align: middle;
            float: left;
            font-size: 14px;
            color: white;
            line-height: 40px;
            padding: 0 12px 0 0;
            box-sizing: border-box;
        }
    </style>
</head>
<body>
<div id="app">
    <el-card style="width: 600px;height: 400px;
    background-color: rgba(100,100,100,0.5);margin: 100px auto;color:white;">
        <h1 style="font-weight: bold;">登录</h1>
        <el-form style="width: 400px; margin: 0 auto" label-width="60px;" >
            <el-form-item>
                <el-input placeholder="请输入用户名" prefix-icon="el-icon-user-solid" v-model="user.username">
                </el-input>
            </el-form-item>
            <el-form-item>
                <el-input placeholder="请输入密码" prefix-icon="el-icon-lock" v-model="user.password">
                </el-input>
            </el-form-item>
            <el-form-item>
                <el-button style="position: relative;" @click="login()" round>登录</el-button>
            </el-form-item>
            <span style="float: right;color: white">还没有用户?<a style="color: #0aa1ed;text-decoration: none;" href="/reg.html">注册</a>一个吧</span>
        </el-form>
    </el-card>
</div>
</body>
<!-- import Vue before Element -->
<script src="js/vue.js"></script>
<!-- import JavaScript -->
<script src="js/eui.js"></script>
<script src="js/axios.min.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function() {
            return {
                user:{
                    username:"",
                    password:""
                }
            }
        },
        methods:{
            login(){
                axios.post("/login",v.user).then(function (response) {
                    if (response.data==1){
                        location.href="/admin.html";
                    }else if (response.data==2){
                        v.$message.error("用户名不存在")
                    }else {
                        v.$message.error("密码错误")
                    }
                })
            }
        }
    })
</script>
</html>